<template>
  <view class="ts-flex ts-column">
    <view class="ts-flex ts-column">
      <ts-banner image='https://via.placeholder.com/750x250' height="250"></ts-banner>
      <ts-search-bar v-model="keywords" @search="doSearch"></ts-search-bar>
    </view>
    <view class="ts-list">
      <view class="ts-list-cell" hover-class="ts-list-cell-hover" v-for="(item,index) in list" :key="index">
        <view class="ts-media-list">
          <view class="ts-flex ts-flex-item ts-column">
            <view class="ts-h5">{{item.address}}</view>
            <view class="ts-flex ts-row" style="justify-content: space-between;">
              <view class="ts-row ts-flex" style="align-items: center;">
                <view class="ts-h5">{{item.time}}</view>
              </view>
              <view class="ts-row ts-flex-item" style="justify-content: flex-end;">
                <block v-if="item.status.length>0">
                  <ts-badge :type="'success'" :text="item.status"></ts-badge>
                </block>
                <ts-badge :type="item.type==='丢失'? 'danger':'primary'" :text="item.type"></ts-badge>
              </view>
            </view>
            <view class="ts-flex ts-column ts-flex-item ts-padding-top ts-padding-bottom">
              <text class="ts-flex">{{item.content}}</text>
            </view>
            <view class="ts-flex ts-row" style="flex-wrap: wrap; align-items: center;">
              <image v-for="(img, index2) in item.images" :key="index2" class="image-box" :src="img"></image>
            </view>
          </view>
        </view>
      </view>
    </view>

    <view class="ts-flex ts-column">
      <ts-load-more :loadingType="loadingType" @tap="getProductList"></ts-load-more>
    </view>

  </view>
</template>

<script>
  import tsBanner from 'components/teaset/components/ts-banner/ts-banner.vue';
  import tsBadge from 'components/teaset/components/ts-badge/ts-badge.vue';
  import tsIcon from 'components/teaset/components/ts-icon/ts-icon.vue';
  import tsSearchBar from 'components/teaset/components/ts-search-bar/ts-search-bar.vue';
  import tsLoadMore from 'components/teaset/components/ts-load-more/ts-load-more.vue';
  import service from 'services/lost-found.js';
  var self;
  export default {
    components: {
      tsBadge,
      tsBanner,
      tsIcon,
      tsSearchBar,
      tsLoadMore,
    },
    data() {
      return {
        uid: 0,
        keywords: '',
        loadingType: 0, //上拉的状态：0-loading前；1-loading中；2-没有更多了
        page: 0,
        list: [],
        // 			list: [{
        // 				content: '雨伞',
        // 				type: '捡到',
        // 				time: '13天前',
        // 				address: '西区创业园',
        // 				contact: '13800138000',
        // 				images: [
        // 					'https://via.placeholder.com/350x150',
        // 					'https://via.placeholder.com/350x150',
        // 					'https://via.placeholder.com/350x150',
        // 				]
        // 			}]
      }
    },
    async onLoad() {
      self = this;
      await this.doSearch();
    },
    async onReachBottom() {
      console.log("onReachBottom");
      await this.getEventListMoreData();
    },
    methods: {
      async doSearch(keywords = '') {
        this.list = [];
        this.page = 0;
        this.loadingType = 0;
        await this.getEventListMoreData();
        // console.log(keywords);
      },
      async getEventListMoreData() {
        //上拉的状态：0-loading前；1-loading中；2-没有更多了
        if (this.loadingType !== 0) {
          return;
        }
        this.loadingType = 1;
        this.page = this.page + 1;
        const data = await service.getEventListByUser(this.uid, this.keywords, this.page);
        if (data == false) {
          self.loadingType = 2; //2-没有更多了
          return;
        } else {
          self.loadingType = 0; //开启新一轮加载
          self.list = self.list.concat(data);
        }
      }
    }
  };
</script>

<style>
  /*  page,
  view {
    display: flex;
    flex-direction: column;
  } */

  .ts-badge {
    margin-right: 20upx;
  }

  .image-box {
    height: 220upx;
    width: 220upx;
    padding-right: 10upx;
    padding-bottom: 10upx;
  }
</style>
